package com.seeyon.apps.kk.manager.logps;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.kk.manager.FreemarkFlowManager;
import com.seeyon.apps.kk.manager.LockBusinessTravelSapManager;
import com.seeyon.apps.kk.manager.LockCheckworkSapManager;
import com.seeyon.apps.kk.manager.LockOvertimeSapManager;
import com.seeyon.apps.kk.manager.LockVacationSapManager;

public class LogpsAbstractManager extends AbstractManager {
	private static final Log log = LogFactory.getLog(LogpsAbstractManager.class);
	private FreemarkFlowManager freemarkFlowManager;
	private LockVacationSapManager lockmanager;
	private LockOvertimeSapManager lockovermanager;
	private LockCheckworkSapManager lockcheckmanager;
	private LockBusinessTravelSapManager lockbussimanager;
	
	public LockVacationSapManager getLockmanager() {
		return lockmanager;
	}
	public void setLockmanager(LockVacationSapManager lockmanager) {
		this.lockmanager = lockmanager;
	}
	public LockOvertimeSapManager getLockovermanager() {
		return lockovermanager;
	}
	public void setLockovermanager(LockOvertimeSapManager lockovermanager) {
		this.lockovermanager = lockovermanager;
	}
	public LockCheckworkSapManager getLockcheckmanager() {
		return lockcheckmanager;
	}
	public void setLockcheckmanager(LockCheckworkSapManager lockcheckmanager) {
		this.lockcheckmanager = lockcheckmanager;
	}
	public LockBusinessTravelSapManager getLockbussimanager() {
		return lockbussimanager;
	}
	public void setLockbussimanager(LockBusinessTravelSapManager lockbussimanager) {
		this.lockbussimanager = lockbussimanager;
	}
	public FreemarkFlowManager getFreemarkFlowManager() {
		return freemarkFlowManager;
	}
	public void setFreemarkFlowManager(FreemarkFlowManager freemarkFlowManager) {
		this.freemarkFlowManager = freemarkFlowManager;
	}

	@Override
	public boolean CxpsSoure() {
		String findneedPs = this.freemarkFlowManager.fltTemplateIntoString(" SELECT * FROM formmain_0160 WHERE FIELD0003 is NULL\r\n" + 
				" AND TO_CHAR(START_DATE,'YYYY-MM-DD')=TO_CHAR(SYSDATE-1,'YYYY-MM-DD')", null);//查询日志表
		List<Map<String, Object>> queryForList = this.jdbcTemplate.queryForList(findneedPs);
		for (Map<String, Object> map : queryForList) {
			String danjuleixing = MapUtils.getString(map, "FIELD0001");
			String yuansj = MapUtils.getString(map, "FIELD0005");
			String logid = MapUtils.getString(map, "ID");
			Map<String,Object> rouse = JSONObject.parseObject(yuansj.replaceAll(" ", ""));
			Map<String, Object> resultMap=new HashMap<String,Object>();
			try {
			if("休假申请单".equals(danjuleixing)) { 
					resultMap = this.lockmanager.SendToGhr(rouse);
			}else if("加班申请单".equals(danjuleixing)) {
					resultMap = this.lockovermanager.AddOvertimeForm(rouse);
			}else if("出差报告".equals(danjuleixing)) {
					resultMap  = this.lockbussimanager.SendToGhr(rouse);
			}else if("考勤确认书".equals(danjuleixing)) {
					resultMap  = lockcheckmanager.addCheckwordForm(rouse);
			}
			} catch (Exception e) {
				e.printStackTrace();
			}
			Map<String,Object> mv = new HashMap<>();
			mv.put("IFDATE", MapUtils.getString(resultMap, "IF_DATE"));
			mv.put("STATUS", MapUtils.getString(resultMap, "STATUS"));
			mv.put("MESSAGER", MapUtils.getString(resultMap, "XIAOXI"));
			mv.put("LOGID", logid);
			String findsql = this.freemarkFlowManager.fltTemplateIntoString("sql/ghr/log/gengxin.ftl", mv);
			this.jdbcTemplate.update(findsql);
		}
		return false;
	}


	 
	
}
